from zeus.operation_service.app.core.common.data_collection.kafka_adpter import ConsumerForKafka
from zeus.operation_service.app.core.alarm_util.comm import connect_prometheus, get_kafka_server


def get_range_data(metric_name: str, labels: dict, start: int, end: int, step: int):
    prometheus = connect_prometheus()
    if prometheus is None:
        return None
    res = prometheus.get_range_metrics(metric_name=metric_name, labels=labels,
                                       start_time=start, end_time=end, step=step)
    return res if res else None


def get_event_data(start_time, end_time, group_id='event_consumer'):
    """
    返回group_id消费的时间段的数据
    """
    kafka_server = get_kafka_server()
    if kafka_server is None:
        return list()
    consumer = ConsumerForKafka(kafka_server, "gala_gopher_event", group_id)
    event_list = consumer.seek_range_time_data(start_time, end_time)
    return event_list
